﻿@model FieldControlViewModel
@{
	string ctlID = Model.Prefix + Model.FieldName;
	string selectCountry = string.Empty;
	string selectProvince = string.Empty;
	string selectCity = string.Empty;
	string selectArea = string.Empty;
	string selectAddress = string.Empty;
	string defaultValue = (!string.IsNullOrEmpty(Model.FieldValue)) ? Model.FieldValue : Model.Settings[2];
	var arrValue = defaultValue.Split(new char[] { ',' });
	selectCountry = (!string.IsNullOrEmpty(arrValue[0])) ? arrValue[0] : "中华人民共和国";
	selectProvince = arrValue[1];
	selectCity = arrValue[2];
	selectArea = arrValue[3];
	selectAddress = arrValue[4];
	string displayCountry = string.Empty;
	string displayProvince = string.Empty;
	string displayCity = string.Empty;
	string displayArea = string.Empty;
	string dataValCountry = string.Empty;
	string dataValProvince = string.Empty;
	string dataValCity = string.Empty;
	string dataValArea = string.Empty;
	string dataValAddress = string.Empty;
	string colClassName = string.Empty;
	switch (Model.Settings[1])
	{
		case "1"://国家+省
			colClassName = "layui-col-xs6 layui-col-sm6 layui-col-md6";
			displayCity = "display:none !important;";
			displayArea = "display:none !important;";
			if (Model.EnableNull)
			{
				dataValCountry = " data-val=\"true\" data-val-required=\"国家不能为空\" ";
				dataValProvince = " data-val=\"true\" data-val-required=\"省不能为空\" ";
				dataValAddress = " data-val=\"true\" data-val-required=\"地址不能为空\" ";
			}
			break;
		case "2"://国家+省+市
			colClassName = "layui-col-xs4 layui-col-sm4 layui-col-md4";
			displayArea = "display:none !important;";
			if (Model.EnableNull)
			{
				dataValCountry = " data-val=\"true\" data-val-required=\"国家不能为空\" ";
				dataValProvince = " data-val=\"true\" data-val-required=\"省不能为空\" ";
				dataValCity = " data-val=\"true\" data-val-required=\"市不能为空\" ";
				dataValAddress = " data-val=\"true\" data-val-required=\"地址不能为空\" ";
			}
			break;
		case "3"://国家+省+市+县
			colClassName = "layui-col-xs3 layui-col-sm3 layui-col-md3";
			if (Model.EnableNull)
			{
				dataValCountry = " data-val=\"true\" data-val-required=\"国家不能为空\" ";
				dataValProvince = " data-val=\"true\" data-val-required=\"省不能为空\" ";
				dataValCity = " data-val=\"true\" data-val-required=\"市不能为空\" ";
				dataValAddress = " data-val=\"true\" data-val-required=\"地址不能为空\" ";
			}
			break;
		case "4"://省+市
			colClassName = "layui-col-xs6 layui-col-sm6 layui-col-md6";
			displayCountry = "display:none !important;";
			displayArea = "display:none !important;";
			if (Model.EnableNull)
			{
				dataValProvince = " data-val=\"true\" data-val-required=\"省不能为空\" ";
				dataValCity = " data-val=\"true\" data-val-required=\"市不能为空\" ";
				dataValAddress = " data-val=\"true\" data-val-required=\"地址不能为空\" ";
			}
			break;
		case "5"://省+市+县
			colClassName = "layui-col-xs4 layui-col-sm4 layui-col-md4";
			displayCountry = "display:none !important;";
			if (Model.EnableNull)
			{
				dataValProvince = " data-val=\"true\" data-val-required=\"省不能为空\" ";
				dataValCity = " data-val=\"true\" data-val-required=\"市不能为空\" ";
				dataValAddress = " data-val=\"true\" data-val-required=\"地址不能为空\" ";
			}
			break;
		case "6"://市+县
			colClassName = "layui-col-xs6 layui-col-sm6 layui-col-md6";
			displayCountry = "display:none !important;";
			displayProvince = "display:none !important;";
			if (Model.EnableNull)
			{
				dataValCity = " data-val=\"true\" data-val-required=\"市不能为空\" ";
				dataValAddress = " data-val=\"true\" data-val-required=\"地址不能为空\" ";
			}
			break;
	}

}
<span class="select-box radius">
	<div class="@colClassName" style="@displayCountry">
		<select lay-ignore class="select" onchange="SelectCountry('@{@ctlID}')" id="@{@ctlID}Country" name="@{@ctlID}Country" @Html.Raw(dataValCountry)></select>
	</div>
	<div class="@colClassName" style="@displayProvince">
		<select lay-ignore class="select" onchange="SelectProvince('@{@ctlID}')" id="@{@ctlID}Province" name="@{@ctlID}Province" @Html.Raw(dataValProvince)></select>
	</div>
	<div class="@colClassName" style="@displayCity">
		<select lay-ignore class="select" onchange="SelectCity('@{@ctlID}')" id="@{@ctlID}City" name="@{@ctlID}City" @Html.Raw(dataValCity)></select>
	</div>
	<div class="@colClassName" style="@displayArea">
		<select lay-ignore class="select" id="@{@ctlID}Area" name="@{@ctlID}Area"></select>
	</div>
</span>
<input type="text" class="layui-input" name="@{@ctlID}Address" id="@{@ctlID}Address" value="@selectAddress" placeholder="详细地址" @Html.Raw(dataValAddress) />
<span class="layui-bg-green" style="display:inline-block;">@Model.Description</span>
<span style="color:red;" data-valmsg-replace="true" data-valmsg-for="@{@ctlID}Country"></span>
<span style="color:red;" data-valmsg-replace="true" data-valmsg-for="@{@ctlID}Province"></span>
<span style="color:red;" data-valmsg-replace="true" data-valmsg-for="@{@ctlID}City"></span>
<span style="color:red;" data-valmsg-replace="true" data-valmsg-for="@{@ctlID}Address"></span>
<script type="text/javascript">
	jQuery(function () {
		InitRegion("@selectCountry", "@selectProvince", "@selectCity", "@selectArea", "@ctlID");
	});
</script>